package com.wallet.provider.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wallet.common.vo.PageResult;
import com.wallet.provider.model.SysUser;
import com.wallet.provider.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class UserController {

    @Autowired
    private SysUserService sysUserService;

    /**
     * 分页查询系统用户
     * @param keywords
     * @param pageNum
     * @param pageSize
     * @param orderName
     * @param orderType
     * @return
     */
    @RequestMapping(value = "/getSysUserList", method = RequestMethod.GET)
    public PageResult<SysUser> getSysUserList(@RequestParam(value="keywords",required = false) String keywords, @RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,@RequestParam("orderName") String orderName,@RequestParam("orderType") String orderType){
        PageHelper.startPage(pageNum, pageSize);
        PageInfo pageInfo =  sysUserService.getSysUserList(keywords,pageNum,pageSize,orderName,orderType);
        return PageResult.getPageResult(pageInfo);
    }

    /**
     * 添加系统用户
     * @param sysUser
     * @return
     */
    @RequestMapping(value = "/addSysUser", method = RequestMethod.POST)
    public boolean addSysUser(@RequestBody  SysUser sysUser){
        return sysUserService.addSysUser(sysUser);
    }

    /**
     * 删除系统用户
     * @param ids
     * @return
     */
    @RequestMapping(value = "/deleteSysUser", method = RequestMethod.POST)
    public boolean deleteSysUser(@RequestParam("ids") String ids){
        return sysUserService.deleteSysUser(ids);
    }

    /**
     * 修改系统用户
     * @param sysUser
     */
    @RequestMapping(value = "/updateSysUser", method = RequestMethod.POST)
    public boolean updateSysUser(@RequestBody  SysUser sysUser){
        return sysUserService.updateSysUser(sysUser);
    }

    /**
     * 验证登录名是否已存在
     * @param username
     * @return
     */
    @RequestMapping(value = "/validUserId", method = RequestMethod.POST)
    public boolean validUserId(@RequestParam("username") String username){
        return sysUserService.validUserId(username);
    }

    /**
     * 根据username根据系统用户
     * @param username
     * @return
     */
    @RequestMapping(value = "/getSysUserByUsername", method = RequestMethod.POST)
    public SysUser getSysUserByUsername(@RequestParam("username") String username){
        return sysUserService.getSysUserByUsername(username);
    }

    /**
     * 根据id查询系统用户
     * @param id
     * @return
     */
    @RequestMapping(value = "/getSysUserById", method = RequestMethod.POST)
    public SysUser getSysUserById(@RequestParam("id") Long id){
        return sysUserService.getSysUserById(id);
    }
}
